﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace XmlDSigEx
{
    public static class TransformFactory
    {
        private static List<ITransformProvider> _Providers = new List<ITransformProvider>();

        static TransformFactory()
        {
            // Default configuration.
            _Providers.Add(new EnvelopedTransformProvider());
            _Providers.Add(new ExcC14NTransformProvider());
            _Providers.Add(new XPathFilter2TransformProvider());
        }

        public static void AddProvider(ITransformProvider Provider)
        {
            lock (typeof(TransformFactory))
            {
                _Providers.Insert(0, Provider);
            }
        }

        public static ITransform GetTransform(string algorithm, XmlDocument documentContext)
        {
            foreach (ITransformProvider Provider in _Providers)
            {
                if (Provider.CanHandle(algorithm))
                    return Provider.GetTransform(documentContext);
            }
            throw new UnknownAlgorithmException("No Provider was registered for the transform.");
        }
    }
}
